



import 'package:flutter/material.dart';
import 'package:flutter/material.dart';

main()=> runApp(CLMyapp());

class CLMyapp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
        home: CLhome()
    );
  }
}
class CLhome extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Scaffold(
        appBar: AppBar(
          title:Text("计数器") ,
        ),
        body: CLbody("hi")
    );
  }
}
class CLbody extends StatefulWidget{
  final message;
  CLbody(this.message);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _CLbodystate();
  }
}

class _CLbodystate extends State<CLbody> {
  int _count = 0;


  @override
  Widget build(BuildContext context) {

    // TODO: implement build
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _getbutton(),
          Text("当前计数$_count",
            style: TextStyle(color: Colors.orange, fontSize: 30),
          ),
          Text("传递的参数：${this.widget.message}")//没有冲突的话，this可以省略
        ],
      ),
    );
  }

  Widget _getbutton() {//注意，这个方法不能放到类外面了
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [

        RaisedButton(
            child: Text("+",style: TextStyle(fontSize: 20),),
            color: Colors.pink,
            onPressed: () {

              setState(() {
                _count++;
              });
            }
        ),
        RaisedButton(
            child: Text("-",style: TextStyle(fontSize: 20),),
            color: Colors.deepOrange,
            onPressed: () { setState(() {
              _count--;
            });})
      ],
    );
  }
}
